﻿angular.module("umbraco").controller("UE.DeleteController",
    function ($scope, dealerResource, notificationsService, treeService, navigationService) {
        var vm = this;
        vm.confirm = true;
        vm.showSuffix = $scope.currentNode.id.indexOf("dealer_");
        console.log(vm.showSuffix);

        $scope.performDelete = function () {
            $scope.currentNode.loading = true;
            dealerResource.delete($scope.currentNode.id).then(function (response) {
                $scope.currentNode.loading = false;
                if (response.ErrorCode == 0) {
                    treeService.removeNode($scope.currentNode);
                    navigationService.hideMenu();
                } else {
                    UmbClientMgr.closeModalWindow();
                    notificationsService.error("Delete Failed", "Delete failed, please try again!");
                }
            });
        }

        $scope.cancel = function () {
            UmbClientMgr.closeModalWindow();
        }
    }
);